﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ctEHAK", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(CtEHAK))]
    public class CtEHAKSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ICtEHAK clazz;
        
        public CtEHAKSerializer(ICtEHAK clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("EhakTyyp");
            if (clazz.EhakTyyp!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EhakTyyp))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : EhakTyyp");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Kood");
            if (clazz.Kood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kood))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Kood");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Nimetus");
            if (clazz.Nimetus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Nimetus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Nimetus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("IsikuteArv");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.IsikuteArv))).ToString());
            Writer.WriteEndElement();
            if (clazz.AlamEHAKud!=null) {
                Writer.WriteStartElement("AlamEHAKud");
                global::Xtee.Core.SerializationMetadata metaAlamEHAKud = this.GetMetaData(clazz.AlamEHAKud);
                Writer.WriteTypeAttribute(metaAlamEHAKud.TypeQualifiedName.Namespace, metaAlamEHAKud.TypeQualifiedName.Name);
                metaAlamEHAKud.NewSerializer(clazz.AlamEHAKud).WriteXml(Writer);
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="EhakTyyp") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ctEHAK>EhakTyyp");
                }
                clazz.EhakTyyp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("EhakTyyp")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ctEHAK>EhakTyyp", Reader.LocalName);
            }
            if (Reader.LocalName=="Kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ctEHAK>Kood");
                }
                clazz.Kood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Kood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ctEHAK>Kood", Reader.LocalName);
            }
            if (Reader.LocalName=="Nimetus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ctEHAK>Nimetus");
                }
                clazz.Nimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Nimetus")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ctEHAK>Nimetus", Reader.LocalName);
            }
            if (Reader.LocalName=="IsikuteArv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ctEHAK>IsikuteArv");
                }
                clazz.IsikuteArv = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("IsikuteArv")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ctEHAK>IsikuteArv", Reader.LocalName);
            }
            if (Reader.LocalName=="AlamEHAKud") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ctEHAK>AlamEHAKud");
                }
                global::Xtee.Core.SerializationMetadata metaAlamEHAKud = this.GetMetaData<CtEHAK.IAlamEHAKudType>(Reader, ">>ctEHAK>AlamEHAKud", "http://producers.rr.xtee.riik.ee/producer/rr");
                clazz.AlamEHAKud = metaAlamEHAKud.NewEntity<CtEHAK.IAlamEHAKudType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("AlamEHAKud");
                    metaAlamEHAKud.NewSerializer(clazz.AlamEHAKud).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>ctEHAK>AlamEHAKud", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(CtEHAK.AlamEHAKudType))]
        public class AlamEHAKudTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected CtEHAK.IAlamEHAKudType clazz;
            
            public AlamEHAKudTypeSerializer(CtEHAK.IAlamEHAKudType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                if (((clazz.EHAK == null) 
                            || (clazz.EHAK.Count < 1m))) {
                    throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "EHAK");
                }
                for (int x = 0; ((clazz.EHAK != null) 
                            && (x < clazz.EHAK.Count)); x = (x + 1)) {
                    Writer.WriteStartElement("EHAK");
                    if (clazz.EHAK[x]!=null) {
                        global::Xtee.Core.SerializationMetadata metaEHAK = this.GetMetaData(clazz.EHAK[x]);
                        Writer.WriteTypeAttribute(metaEHAK.TypeQualifiedName.Namespace, metaEHAK.TypeQualifiedName.Name);
                        metaEHAK.NewSerializer(clazz.EHAK[x]).WriteXml(Writer);
                    }
                    else {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : EHAK");
                    }
                    Writer.WriteEndElement();
                }
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                clazz.EHAK = new System.Collections.Generic.List<global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.ICtEHAK>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "EHAK")); ) {
                    if (Reader.LocalName=="EHAK") {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>ctEHAK>AlamEHAKud>EHAK");
                        }
                        global::Xtee.Core.SerializationMetadata metaEHAK = this.GetMetaData<global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.ICtEHAK>(Reader, "ctEHAK", "http://producers.rr.xtee.riik.ee/producer/rr");
                        global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.ICtEHAK item = metaEHAK.NewEntity<global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.ICtEHAK>();
                        clazz.EHAK.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("EHAK");
                            metaEHAK.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    else {
                        throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>ctEHAK>AlamEHAKud>EHAK", Reader.LocalName);
                    }
                }
                if ((clazz.EHAK.Count < 1m)) {
                    throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "EHAK");
                }
            }
        }
    }
}
